package Mailer;

use strict;
use warnings;

require Exporter;

our @ISA = qw(Exporter);

our %EXPORT_TAGS = (
    'all' => [
        qw(
            &send_receipt &send_feedback
        )
    ]
);

our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } );

our @EXPORT = qw(
  &send_receipt &send_feedback
);

our $VERSION = '0.01';

sub send_feedback {
    my( $email, $message ) = @_;

    open MAIL, "| /usr/lib/sendmail -t -i"
        or die "Could not open sendmail: $!";

    print MAIL <<END_OF_MESSAGE;
To: webmaster\@scripted.com
Reply-To: $email
Subject: Web Site Feedback

Feedback from a user:

$message
END_OF_MESSAGE

    close MAIL or die "Error closing sendmail: $!";
}

sub send_receipt {
    my $email = shift;
    my $from_email = "chimen\@localhost";
    my $from_name = "Chimen Chen";

    open MAIL, "| /usr/lib/sendmail -t -F'$from_name' -f'$from_email'"
        or die "Could not open sendmail: $!";
    print MAIL <<END_OF_MESSAGE;
To: $email
Subject: [keepit] Welcome

Welcome to "keepit" bookmark service.</p>
* You are already registered to this service.</p>

*** start "keepit" ***

Please click the following link to register, and follow the instruction as displayed.

http://localhost/cgi-bin/bmark.cgi?hl=en&e=chime%40sjtu.edu.cn&s=2da19a4c2cfc620a3dd3dbeee7305535 

*** unregister ***

Please click the following link to unregister.

http://localhost/cgi-bin/delete.cgi?hl=en&e=chime%40sjtu.edu.cn&s=2da19a4c2cfc620a3dd3dbeee7305535


END_OF_MESSAGE

    close MAIL or die "Error closing sendmail: $!";
}

1;
